package org.example.model;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;




/**
 * @description TODO
 * @author sats@jz
 * @date 2024年12月27日 13:19
 *
 * key层级结构：
 * root
 *      /serviceName:version
 *                          /Host:port:
 *
 *
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ServiceMetaInfo {
    private String serviceName;
    @Builder.Default
    private String serviceVersion = "1.0";
    private String serviceHost;
    private Integer servicePort;
    @Builder.Default
    private String serviceGroup = "default";

    public String getServiceKey() {
        // 后续可扩展服务分组
        // return String.format("%s:%s:%s", serviceName, serviceVersion, serviceGroup);
        return String.format("%s:%s", serviceName, serviceVersion);
    }

    public String getServiceNodeKey(){
        return String.format("%s/%s:%s", getServiceKey(), serviceHost, servicePort);
    }

    public String getServiceAddress(){
        if(!StrUtil.contains(serviceHost, "http")){
            return String.format("http://%s:%s", serviceHost, servicePort);
        }
        return String.format("%s:%s", serviceHost, servicePort);
    }

}
